<?php

/**
 *  @FileComment            [后台用户模型]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：AdminModel.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-6 1:53:20
 *  *
 */
class AdminModel extends Model {

        public $table = 'admin';
        public $validate = array(
            array('adminname', 'nonull', '用户名不能为空', 2, 3),
            array('password', 'nonull', '密码不能为空', 2, 3),
            array('adminname', '_isset', '用户名已存在', 2, 3)
        );
        public $auto = array(
            array('password', '_md5', 'method', 2, 3)
        );

        public function _md5($data) {
                return md5($data);
        }

        public function _isset($name, $value, $msg, $arg) {
                $data = $this->where(array('adminname' => $value))->find();
                if (!empty($data)) {
                        return $msg;
                } else {
                        return true;
                }
        }

        public function get_data() {
                return $this->all();
        }

        public function get_one_data($where) {
                return $this->where($where)->find();
        }

        public function del_data($aid) {
                $data = K('AdminRole')->where(array('aid' => $aid))->find();
                if (!empty($data)) {
                        return false;
                }
                return $this->where(array('aid' => $aid))->del();
        }

        public function add_user() {
                return $this->add();
        }

}
